import pandas as pd
import json


def read_csv(file_path, column_name):
    """

    :param file_path:
    :param column_name:
    :return:
    """
    data = pd.read_csv(file_path)
    result = list()
    record_num = int(data.describe().iloc[0, 0])
    for i in range(record_num):
        record = data.iloc[i,:]
        a = (json.loads(record[column_name]))
        result.append(a)
    return result


def get_shapes(data_df):

    shapes = []
    for name, group in data_df.groupby(['序号', '长度', '宽度','纹理']):
        p_id = str(name[0])
        length = int(name[1])
        width = int(name[2])
        texture = int(name[3])
        shape = {'p_id': p_id,
                 'length': length,
                 'width': width,
                 'texture': texture }
        shapes.append(shape)

    return shapes


def get_shapes_from_result(file_path):
    shapes = read_csv(file_path, "零件外轮廓线坐标")
    return shapes


